<template>
  <el-dialog :title="this.$i18n.t('components.violationManagement')" :close-on-click-modal="false" :visible.sync="visible" width="35%">
    <el-form
      :model="dataForm"
      :rules="dataRule"
      ref="dataForm"
      @keyup.enter.native="dataFormSubmit()"
      label-width="80px"
    >
      <el-form-item :label="this.$i18n.t('components.handler')" prop="handler">
        <el-input v-model="dataForm.handler" :disabled="true"></el-input>
      </el-form-item>
      <el-form-item :label="this.$i18n.t('components.processingStatus')" prop="status">
        <!-- 1平台进行下线 2 重新申请，等待审核 3.审核通过 4 审核未通过 -->
        <el-tag v-if="dataForm.status === 1" size="small" type="danger">{{$t("components.platformOffline")}}</el-tag>
        <el-tag v-else-if="dataForm.status === 2" size="small" type="warning">{{$t("groups.moderated")}}</el-tag>
        <el-tag v-else-if="dataForm.status === 3" size="small" type="success">{{$t("productComm.pass")}}</el-tag>
        <el-tag v-else-if="dataForm.status === 4" size="small" type="danger">{{$t("components.auditNotPassed")}}</el-tag>
        <el-tag v-else size="small" type="warning">{{$t("product.other")}}</el-tag>
      </el-form-item>
      <el-form-item :label="this.$i18n.t('components.reasonForOffline')" prop="offlineReason">
        <el-input
          type="textarea"
          :autosize="{ minRows: 2, maxRows: 10}"
          maxlength="200"
          v-model="dataForm.offlineReason"
          :disabled="true"
        ></el-input>
      </el-form-item>
      <el-form-item :label="this.$i18n.t('components.offlineTime')" prop="createTime">
        <el-input v-model="dataForm.createTime" :disabled="true"></el-input>
      </el-form-item>
      <el-form-item
        v-if="dataForm.status === 1 || dataForm.status === 4"
        :label="this.$i18n.t('components.reasonForApply')"
        prop="reapplyReason"
      >
        <el-input
          type="textarea"
          :autosize="{ minRows: 2, maxRows: 10}"
          maxlength="200"
          v-model="reapplyReason"
          :disabled="!(dataForm.status === 1 || dataForm.status === 4)"
        ></el-input>
      </el-form-item>
    </el-form>
    <el-divider></el-divider>
    <div>
      <div style="margin-bottom:10px">
        <strong>{{$t("components.applicationLog")}}</strong>
      </div>
      <div v-for="item in dataForm.offlineHandleEventItemList" :key="item.eventItemId">
        <el-row type="flex" justify="space-around">
          <el-col :span="5">
            <strong>{{$t("components.applicationTime")}}：</strong>
          </el-col>
          <el-col :span="24">
            <span class="content-color">{{item.createTime}}</span>
          </el-col>
        </el-row>
        <el-row type="flex" justify="space-around">
          <el-col :span="5">
            <strong>{{$t("components.reasonForApply")}}：</strong>
          </el-col>
          <el-col :span="24">
            <div>
              <span class="content-color">{{item.reapplyReason}}</span>
            </div>
          </el-col>
        </el-row>
        <el-row type="flex" justify="space-around" v-if="item.auditTime">
          <el-col :span="5">
            <strong>{{$t("components.reviewTime")}}：</strong>
          </el-col>
          <el-col :span="24">
            <div>
              <span class="content-color">{{item.auditTime}}</span>
            </div>
          </el-col>
        </el-row>
        <el-row type="flex" justify="space-around" v-if="item.refuseReason">
          <el-col :span="5">
            <strong>{{$t("components.denialReason")}}：</strong>
          </el-col>
          <el-col :span="24">
            <div>
              <span class="content-color">{{item.refuseReason}}</span>
            </div>
          </el-col>
        </el-row>
        <div style="width:50%">
          <el-divider />
        </div>
      </div>
    </div>

    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false" size="mini">{{$t("crud.filter.cancelBtn")}}</el-button>
      <el-button
        type="primary"
        size="mini"
        :disabled="dataForm.status !== 1 && dataForm.status !== 4"
        @click="dataFormSubmit()"
      >{{$t("components.submitApplication")}}</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  data () {
    return {
      visible: false,
      dataForm: {
        eventId: null,
        handleType: null,
        handleId: null,
        shopId: null,
        handlerId: null,
        status: null,
        offlineReason: null
      },
      reapplyReason: '',
      id: 0,
      dataRule: {
      }
    }
  },
  props: {
    selectUrl: {
      default: '',
      type: String
    },
    applyUrl: {
      default: '',
      type: String
    }
  },
  methods: {
    init (id) {
      this.id = id || 0
      this.visible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].resetFields()
        if (this.id) {
          this.$http({
            url: this.$http.adornUrl(this.selectUrl + '/' + id),
            method: 'get',
            params: this.$http.adornParams()
          }).then(({ data }) => {
            if (!data) {
              this.$message({
                message: this.$i18n.t('components.retryAfterRefresh'),
                type: 'error',
                duration: 1500,
                onClose: () => {
                  this.reapplyReason = ''
                  this.visible = false
                  this.$emit('refreshDataList')
                }
              })
            }
            this.dataForm = data
          })
        }
      })
    },
    // 表单提交
    dataFormSubmit () {
      if (!this.reapplyReason) {
        this.$message.error(this.$i18n.t('components.applicaEmpty'))
        return
      }
      this.$confirm(this.$i18n.t('components.areYouSureAtion'), this.$i18n.t('text.tips'), {
        confirmButtonText: this.$i18n.t('crud.filter.submitBtn'),
        cancelButtonText: this.$i18n.t('crud.filter.cancelBtn')
      }).then(() => {
        this.$http({
          url: this.$http.adornUrl(this.applyUrl),
          method: 'post',
          data: this.$http.adornData({
            eventId: this.dataForm.eventId,
            handleId: this.id,
            reapplyReason: this.reapplyReason
          })
        }).then(({ data }) => {
          this.$message({
            message: this.$i18n.t('publics.operation'),
            type: 'success',
            duration: 1500,
            onClose: () => {
              this.reapplyReason = ''
              this.visible = false
              this.$emit('refreshDataList')
            }
          })
        })
      })
    }
  }
}
</script>
<style  lang="scss" scoped>
.content-color {
  color: #4395ff;
}
</style>
